package org.dtrd.modules.content.articles.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.dtrd.modules.content.articles.entity.bean.FaqCategory;
import org.dtrd.modules.content.articles.service.IDtrdExtEmsFaqCategoryService;
import org.dtrd.modules.faq.entity.po.DtrdExtEmsYwFaqCategory;
import org.dtrd.modules.faq.mapper.DtrdExtEmsYwFaqCategoryMapper;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
@DS("multi-datasource1")
public class IDtrdExtEmsFaqCategoryServiceImpl extends ServiceImpl<DtrdExtEmsYwFaqCategoryMapper, DtrdExtEmsYwFaqCategory> implements IDtrdExtEmsFaqCategoryService {
    @Override
    public List<FaqCategory> selectCategories() {
        LambdaQueryWrapper<DtrdExtEmsYwFaqCategory> query = Wrappers.lambdaQuery(DtrdExtEmsYwFaqCategory.class)
                .eq(DtrdExtEmsYwFaqCategory::getIsDel,0)
                .orderByDesc(DtrdExtEmsYwFaqCategory::getDataId);
        List<DtrdExtEmsYwFaqCategory> list = baseMapper.selectList(query);
        if (list != null) {
            List<FaqCategory> dataList = new ArrayList<>(list.size());
            list.stream().map(po -> new FaqCategory().parseFromPO(po)).forEach(dataList::add);
            return dataList;
        }
        return null;
    }
}
